package com.zker.missyou.validators;/*
 * ClassName: PasswordValidator
 * Package : com.zker.missyou.validators
 * Description:
 * @Author zKer
 * @Create 2024/6/28 15:22
 */

import com.zker.missyou.dto.PersonDTO;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class PasswordValidator implements ConstraintValidator<PasswordEquals, PersonDTO> {
    int min;
    int max;
    @Override
    public void initialize(PasswordEquals constraintAnnotation) {
        this.min = constraintAnnotation.min();
        this.max = constraintAnnotation.max();
    }

    @Override
    public boolean isValid(PersonDTO personDTO, ConstraintValidatorContext constraintValidatorContext) {
        String password1 = personDTO.getPassword1();
        String password2 = personDTO.getPassword2();
        return password1.equals(password2);
    }
}
